package com.example.demo.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdUtil;
import com.example.demo.dao.DdxxMapper;
import com.example.demo.dto.DdxxAddInputDTO;
import com.example.demo.dto.DdxxQueryParam;
import com.example.demo.dto.DdxxQueryResult;
import com.example.demo.model.DemoYxDdxx;
import com.example.demo.service.DdxxService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author ricky
 * @date 2022/1/28
 */
@Service
public class DdxxServiceImpl implements DdxxService {
    @Resource
    private DdxxMapper ddxxMapper;

    @Override
    public String addDdxx(DdxxAddInputDTO inputDTO) {
        DemoYxDdxx ddxx = BeanUtil.copyProperties(inputDTO, DemoYxDdxx.class);
        ddxx.setDdbh(IdUtil.fastSimpleUUID());
        ddxx.setSfsc("N");
        ddxx.setCjsj(new Date());
        ddxx.setZhxgsj(new Date());
        int i = ddxxMapper.insert(ddxx);
        if (i != 1) {
            throw new RuntimeException("添加失败");
        }
        return ddxx.getDdbh();
    }

    @Override
    public List<DdxxQueryResult> queryDdxx(DdxxQueryParam inputDTO) {
        return ddxxMapper.queryDdxx(inputDTO);
    }
}
